<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Task;
use App\Controller\AbstractController;
use App\Model\User;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Psr\Container\ContainerInterface;
use Hyperf\Logger\LoggerFactory;
use Hyperf\Crontab\Annotation\Crontab;

/**
 * @Crontab(name="Adduser", rule="* * * * * *", callback="index", singleton=true, memo="这是一个示例的定时任务")
 */
class AdduserController extends AbstractController
{
    /**
     * @var \Psr\Log\LoggerInterface
     */
    protected $logger;
    public function __construct(LoggerFactory $loggerFactory)
    {
        // 第一个参数对应日志的 name, 第二个参数对应 config/autoload/logger.php 内的 key
        $this->logger = $loggerFactory->get('log', 'default');
    }

    public function index()
    {

        $user = new User();
        $user->username = 'taskman'.rand(1,10000);
        $user->email = '651738941'.rand(0, 1000).'@qq.com';
        $user->created_at = time();
        $users = $user->save();
        $this->logger->info("Your log message.");
//        return [
//            'message' => "add success！！",
//        ];
    }
}
